<!--
 * @company : 版权所属 四川北星惯牌科技有限公司
 * @contact : 刘经理 19326416371
 -->
<template>
	<view class="content w100">
		<template v-if="teamInfo.list.length>0">
			<myTeamItemVue v-for="(item,index) in teamInfo.list" @restList="restList" :groupInfo="item"
				:key="item.t_id">
			</myTeamItemVue>
			<view class="view-more" @click="getMoreTeamList">
				<up-loadmore :status="teamInfo.status" />
			</view>
		</template>
		<view class="not-list-view" v-else>
			<text class="text">暂无比赛数据~</text>
		</view>
	</view>
</template>

<script setup>
	import teamItemVue from '@/components/main/teamItem.vue';
	import myTeamItemVue from '@/page_store/components/myTeamItem.vue';
	const storeId = ref(0);
	const teamInfo = reactive({
		list: [],
		status: 'loadmore',
		pageSize: 1
	});
	onLoad((option) => {
		if (option.storeId) {
			storeId.value = option.storeId;
			getTeamList()
		} else {
			uni.$u.toast('未找到相关信息')
		}
	})
	onReachBottom(() => { //触底刷新
		getMoreTeamList()
	})
	const getMoreTeamList = () => {
		if (teamInfo.status == 'nomore' || teamInfo.status == 'loading') return;
		teamInfo.status = 'loading';
		setTimeout(() => {
			getTeamList();
		}, 600)
	}
	const getTeamList = async () => {
		const res = await $Api.store.getGroup({
			id: storeId.value,
			page: teamInfo.pageSize
		})
		if (res.code === 1) {
			if (res.data.list.length > 0) {
				let arr = [];
				arr = res.data.list.map(val => {
					let imageList = [];
					if (val.juli) {
						val.juli = parseFloat(val.juli).toFixed(2)
					}
					if (val.image) {
						if (typeof val.image === 'string') {
							imageList = val.image.split(',');
						} else if (Array.isArray(val.image)) {
							val.image.forEach(item => {
								imageList.push(item.url);
							})
						}
					}
					return {
						...val,
						imageList: imageList
					}
				})
				teamInfo.list = [...teamInfo.list, ...arr];
				console.log('teamInfo.list', teamInfo.list);
			}
			if (res.data.totalPage && res.data.totalPage > teamInfo.pageSize) {
				teamInfo.status = 'loadmore';
				teamInfo.pageSize++;
			} else {
				teamInfo.status = 'nomore';
			}
		} else {
			uni.$u.toast(res.msg);
		}
	}
	const restList = () => {
		teamInfo.status = 'loadmore';
		teamInfo.pageSize = 1;
		teamInfo.list = [];
		getTeamList();
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 20rpx;
	}
</style>